﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shop.Model;
using System.Web.Mvc;
using Shop.Framework.Services;

namespace Shop.Framework.Page {
    public class CMS_ProductDetailPage:ViewPage {
        
        public Product ProductDetail { get; set; }
        public int IdCategory { get; set; }
        public List<Designer> DesignerList { get; set; }

        protected override void OnInit(EventArgs e) {
            //TODO: Encapsulate
            ProductDetail = ViewData["ProductDetail"] as Product;
            //TODO: Encapsulate 
            IdCategory = Convert.ToInt32(ViewData["IdCategory"]);

            DesignerService service = new DesignerService();
            DesignerList = service.GetDesigners();
            if (ProductDetail.IdDesigner != 0) {
                Designer d = DesignerList.FirstOrDefault(des => des.IdDesigner == ProductDetail.IdDesigner);
                DesignerList.Remove(d);
                DesignerList.Insert(0, d);
            } else {
                ProductDetail.IdDesigner = DesignerList[0].IdDesigner;
                ProductDetail.DateEncoded = DateTime.Now;
            }
            base.OnInit(e);
        }

    }
}
